package com.itcast.rabbitmq.config;

import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RabbitConfig {

    //定义交换机
    public static final String ITEM_TOPIC_EXCHANG = "item_topic_exchang";

    //定义队列
    public static final String ITEM_QUEUE = "item_queue";

    //申明交换机
    @Bean("itemTopicExchang")
    public Exchange getExchange(){
        return ExchangeBuilder.topicExchange(ITEM_TOPIC_EXCHANG).build();
    }

    //申明队列
    @Bean("itemQueue")
    public Queue getQueue(){
        return QueueBuilder.durable(ITEM_QUEUE).build();
    }

    //绑定队列到交换机
    @Bean
    public Binding itemQueueExchange(@Qualifier("itemTopicExchang") Exchange exchange,
                                     @Qualifier("itemQueue") Queue queue){
        return BindingBuilder.bind(queue).to(exchange).with("item.#").noargs();
    }

}
